<?php
namespace app\home\model;
use \think\Db;

class TopicnewsModel
{
    /**
     * 话题详情
     */
    public function topicDetails($id){
        $topicDetails = Db::table('topics')->find($id);
        return $topicDetails;
    }

    /**
     * 话题评论详情
     */
    public function topicCommentDetails($id){
        $topicCommentDetails = Db::table('topic_news')->where('topic_id', $id)->order('reply_time desc')->select();
        return $topicCommentDetails;
    }

    /**
     * 发表评论
     */
    public function addComment($data){
        $addComment = Db::table('topic_news')->insert($data);
        return $addComment;
    }

    /**
     * 话题评论数量
     */
    public function topicCommentDetailsCount($id){
        $topicCommentDetailsCount = Db::table('topic_news')->where('topic_id', $id)->count();
        return $topicCommentDetailsCount;
    }

    /**
     * 查询用户
     */
    public function user_name($user_id){
        $user_name = Db::table('users')->field('user_name')->find($user_id);
        return $user_name;
    }

}